package net.openvision.music.ui.render;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.LayoutManager;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI;

import net.openvision.music.ui.BasicMusicScoreUI;

public abstract class GenericUI<T extends JComponent> extends ComponentUI {
	protected T component;
	protected LayoutManager defaultLayout;
	protected Border defaultBorder;

	public static ComponentUI createUI(JComponent c) {
		return new BasicMusicScoreUI();
	}
	
	public GenericUI() {
		this(null, BorderFactory.createEmptyBorder());
	}
	
	public GenericUI(LayoutManager layout, Border border) {
		defaultLayout = layout;
		defaultBorder = border;
	}

	@SuppressWarnings("unchecked")
	public void installUI(JComponent c) {
		this.component = (T) c;
		installDefaults();
		installComponents();
		installListeners();

		c.setBackground(Color.WHITE);
		c.setLayout(defaultLayout); // the default layout
		c.setBorder(defaultBorder); // the default Border
	}

	public void uninstallUI(JComponent c) {
		c.setLayout(null);
		uninstallListeners();
		uninstallComponents();
		uninstallDefaults();

		this.component = null;
	}

	public void installDefaults() {

	}

	public void installComponents() {
	}

	public void installListeners() {

	}

	public void uninstallDefaults() {

	}

	public void uninstallComponents() {

	}

	public void uninstallListeners() {

	}

	@Override
	public abstract void paint(Graphics g, JComponent c);
}
